package cn.iocoder.yudao.module.apijson.controller.admin.access.vo;

import apijson.RequestMethod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Schema(description = "管理后台 - 权限配置(必须) AccessAllDataRespVO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AccessAllDataRespVO {
    @Schema(description = "外部调用的表别名")
    private String alias;
    @Schema(description = "是否允许全部方法")
    private Boolean methodsBool;
    @Schema(description = "是否允许方法")
    private Boolean get, head, gets, heads, post, put, delete, crud;


    public void setMethods(Map<String, Boolean> methods) {
        Boolean get = methods.get(RequestMethod.GET.name());
        this.get = get;
        Boolean head = methods.get(RequestMethod.HEAD.name());
        this.head = head;
        Boolean getS = methods.get(RequestMethod.GETS.name());
        this.gets = getS;
        Boolean headS = methods.get(RequestMethod.HEADS.name());
        this.heads = headS;
        Boolean post = methods.get(RequestMethod.POST.name());
        this.post = post;
        Boolean put = methods.get(RequestMethod.PUT.name());
        this.put = put;
        Boolean delete = methods.get(RequestMethod.DELETE.name());
        this.delete = delete;
        Boolean crud = methods.get(RequestMethod.CRUD.name());
        this.crud = crud;
        methodsBool = get && head && getS && headS && post && put && delete && crud;
    }
}
